'use strict';

module.exports = appInfo => {
  const config = exports = {};
  // mysql插件配置
  config.mysql = {
    client: {
      host: 'localhost',
      port: '3306',
      user: 'root',
      password: 'root',
      database: 'egg_main',
    },
  };
  // mysql的orm映射插件配置
  config.sequelize = {
    datasources: [
      {
        delegate: 'model', // 加载所有的模型到 app.model and ctx.model
        baseDir: 'model', // 要加载的模型目录`app/model/*.js`
        database: config.mysql.client.database,
        dialect: 'mysql',
        host: config.mysql.client.host,
        port: config.mysql.client.port,
        username: config.mysql.client.user,
        password: config.mysql.client.password,
        timezone: 'Asia/Shanghai', // 时间差
        benchmark: true,
        define: {
          freezeTableName: true, // 禁止数据读写时给表赋别名(as)
          underscored: true,
          timestamps: false, // 为模型添加createdAt和updatedAt字段
          raw: true,
        },
      },
      {
        delegate: 'logModel', // 加载所有的模型到 app.logModel and ctx.logModel
        baseDir: 'model_log', // 要加载的模型目录 `app/admin_model/*.js`
        database: 'egg_log',
        dialect: 'mysql',
        host: config.mysql.client.host,
        port: config.mysql.client.port,
        username: config.mysql.client.user, // 'log',
        password: config.mysql.client.password,
        timezone: 'Asia/Shanghai',
        benchmark: true,
        define: {
          freezeTableName: true, // 禁止数据读写时给表赋别名(as)
          underscored: true,
          timestamps: false, // 为模型添加createdAt和updatedAt字段
          raw: true,
        },
      },
    ],
  };

  // redis 插件配置
  config.redis = {
    client: {
      port: 6379, // Redis port
      host: '127.0.0.1', // Redis host
      password: '123456',
      db: 0,
    },
  };

  return config;
};
